﻿using Abp.Application.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SportsPlatform.SqlExecuter
{
    /// <summary>
    /// SQL语句仓储库
    /// </summary>
    public interface ISqlExecuterRepository : IApplicationService
    {
        /// <summary>
        /// 执行SQL返回IEnumerable
        /// </summary>
        /// <typeparam name="T">对象实体</typeparam>
        /// <param name="strSql">sql语句</param>
        /// <returns></returns>
        IEnumerable<T> Query<T>(string strSql);

        /// <summary>
        /// 执行SQL返回IEnumerable
        /// </summary>
        /// <typeparam name="T">对象实体</typeparam>
        /// <param name="strSql">sql语句</param>
        /// <returns></returns>
        Task<IEnumerable<T>> QueryAsync<T>(string strSql);

        /// <summary>
        /// 执行SQL返回IEnumerable
        /// </summary>
        /// <typeparam name="T">对象实体</typeparam>
        /// <param name="strSql">SQL语句</param>
        /// <param name="param">参数model</param>
        /// <returns></returns>
        IEnumerable<T> Query<T>(string strSql, object param);

        /// <summary>
        /// 执行SQL返回IEnumerable
        /// </summary>
        /// <typeparam name="T">对象实体</typeparam>
        /// <param name="strSql">SQL语句</param>
        /// <param name="param">参数model</param>
        /// <returns></returns>
        Task<IEnumerable<T>> QueryAsync<T>(string strSql, object param);

        /// <summary>
        /// 执行SQL返回一个对象
        /// </summary>
        /// <typeparam name="T">对象实体</typeparam>
        /// <param name="strSql">SQL语句</param>
        /// <returns></returns>
        T QueryFirst<T>(string strSql);

        /// <summary>
        /// 执行SQL返回一个可为空的对象
        /// </summary>
        /// <typeparam name="T">对象实体</typeparam>
        /// <param name="strSql">SQL语句</param>
        /// <returns></returns>
        T QueryFirstOrDefault<T>(string strSql);

        /// <summary>
        /// 执行SQL返回一个对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql"></param>
        /// <returns></returns>
        Task<T> QueryFirstAsync<T>(string strSql);

        /// <summary>
        /// 执行SQL
        /// </summary>
        /// <param name="strSql">SQL语句</param>
        /// <param name="param">参数</param>
        /// <returns>1成功，0执行失败</returns>
        int Execute(string strSql, object param);

        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="strProcedure">过程名</param>
        /// <returns>1成功，0执行失败</returns>
        int ExecuteStoredProcedure(string strProcedure);

        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="strProcedure">过程名</param>
        /// <param name="param">参数</param>
        /// <returns>1成功，0执行失败</returns>
        int ExecuteStoredProcedure(string strProcedure, object param);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="T">实体对象</typeparam>
        /// <param name="innerSql">SQL语句</param>
        /// <param name="page">页码</param>
        /// <param name="pageSize">当前页码中数据的数量</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        IEnumerable<T> QueryByPage<T>(string innerSql, int page, int pageSize, object param);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="T">实体对象</typeparam>
        /// <param name="innerSql">SQL语句</param>
        /// <param name="page">页码</param>
        /// <param name="pageSize">当前页码中数据的数量</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        Task<IEnumerable<T>> QueryByPageAsync<T>(string innerSql, int page, int pageSize, object param);

        /// <summary>
        /// 分页查询数据
        /// </summary>
        /// <typeparam name="T">实体对象</typeparam>
        /// <param name="innerSql">SQL语句</param>
        /// <param name="skip">跳过数量</param>
        /// <param name="take">返回数量</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        IEnumerable<T> QueryBySkip<T>(string innerSql, int skip, int take, object param);

        /// <summary>
        /// 分页查询数据
        /// </summary>
        /// <typeparam name="T">实体对象</typeparam>
        /// <param name="innerSql">SQL语句</param>
        /// <param name="skip">跳过数量</param>
        /// <param name="take">返回数量</param>
        /// <param name="param">参数</param>
        /// <returns></returns>
        Task<IEnumerable<T>> QueryBySkipAsync<T>(string innerSql, int skip, int take, object param);
    }
}
